import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;

import HelloApp.Hello;
import HelloApp.HelloHelper;

public class HelloClient {
	static Hello helloImpl;
	public static void main(String[] args) {
		try {
			//创建一个ORB实例
			ORB orb = ORB.init(args, null);
			//获取根名称上下文
			org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
			NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
			//从命名上下文中获取接口实现对象
			String name = "Hello";
			helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));
			//调用接口对象的方法
			System.out.println("Obtained a handle on server object:" + helloImpl);
			System.out.println(helloImpl.sayHello());
			helloImpl.shutdown();
		} catch (InvalidName e) {
			e.printStackTrace();
		} catch (NotFound e) {
			e.printStackTrace();
		} catch (CannotProceed e) {
			e.printStackTrace();
		} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
			e.printStackTrace();
		}
		
	}
}
